package com.longyn.sensor;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 传感器工厂
 * @author longyn 2023/6/10
 * @version 1.0.0
 */
public class SensorFactory {

    private static final Map<String, Sensor> sensorMap = new ConcurrentHashMap<>();


    /**
     * 获取传感器
     */
    public static <T extends Sensor> Sensor getSensor(Class<T> sensorClass) {
        try {
            Sensor sensor = sensorMap.get(sensorClass.getName());
            if (sensor == null) {
                return sensorClass.newInstance();
            }
            return sensor;
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return null;
    }
}
